package huawei;

import java.util.Scanner;

public class Test_z_002 {
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        while (in.hasNextLine()) {// 注意，如果输入是多个测试用例，请通过while循环处理多个测试用例
            String  str1 = in.next();
            String  str2 = in.next();
            System.out.println(maxCommonStr(str1, str2));
        }
    }

    private static String maxCommonStr(String str1, String str2) {
        if (str1 == null || str2 == null) {
            return null;
        }
        String longStr = str1.length() >= str2.length() ? str1 : str2;
        String shortStr = str1.length() > str2.length() ? str2 : str1;
        int shortLen = shortStr.length();
        for (int i = 0; i < shortLen; i++) {
            // 左右指针向中间逼近
            for (int left = 0, right = shortLen - i; left <= shortLen && right <= shortLen; left++, right++) {
                String s = shortStr.substring(left, right);
                if (longStr.contains(s)) {
                    return s;
                }
            }
        }
        return null;
    }
}
